package hu.u_szeged.inf.ovrt.filelister.core.workflow;

import hu.u_szeged.inf.ovrt.filelister.commands.Command;
import hu.u_szeged.inf.ovrt.filelister.core.exception.ModuleNotFoundException;

import java.util.Map;

/**
 * CommandFactory implementation.
 */
public class SimpleCommandFactory implements CommandFactory {
    private Map<String, ? extends Command> commands;

    @Override
    public Command getCommand(String commandStr) throws ModuleNotFoundException {
        Command command = null;

        if (commands.containsKey(commandStr)) {
            command = commands.get(commandStr);
        } else {
            throw new ModuleNotFoundException(commandStr + " invalid comand!");
        }

        return command;
    }

    public void setCommands(Map<String, ? extends Command> commands) {
        this.commands = commands;
    }
}
